package logic

import (
	"context"
	"goodsrpc/goods"
	"goodsrpc/internal/svc"
	"goodsrpc/mysql"
	"gorm.io/gorm"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseAddLogic) HouseAdd(in *goods.HouseAddRequest) (*goods.HouseAddResponse, error) {
	// todo: add your logic here and delete this line
	house := mysql.House{
		Model:       gorm.Model{},
		UserId:      in.UserId,
		Name:        in.Name,
		Price:       float64(in.Price),
		FacePrice:   float64(in.FacePrice),
		HouseNumber: in.HouseNumber,
		ListingTime: in.ListingTime,
		State:       in.State,
	}
	mysql.DB.Debug().Create(&house)

	return &goods.HouseAddResponse{
		Id: int64(house.ID),
	}, nil
}
